<template>
  <div>
    {{ goodsList }}
  </div>
</template>

<script>
import {
  ref,
  nextTick
} from "vue";
import { useStore } from "vuex";
export default {
  name: "temp",
  setup() {
    const store = useStore(); // 使用vuex
    let goodsList = ref([]);
    
    const addCar = () => { // 添加购物车
      // 调用vuex cart模块mutations中的addToCar方法
      store.commit("cart/addToCar", {
        id: 2,
        title: "临时数据",
        desc: "描述",
        thumb_path: imgUrl,
        sell_price: 12.8,
        count: 10,
        select: false
      })
    }

    const getGoodsList = () => { // 获取购物车数据
      nextTick(() => {
        goodsList.value = store.getters.shopCar;
      });
    }

    getGoodsList();

    return {
      goodsList,
      addCar,
      getGoodsList,
    }
  }
}
</script>